package main

import (
	"github.com/gin-contrib/sessions"
	"github.com/gin-contrib/sessions/cookie"
	"github.com/gin-gonic/gin"
)

func main() {
	engine := gin.Default() // gin Engine对象

	// store := memstore.NewStore([]byte("secret"))
	store := cookie.NewStore([]byte("secret")) // 采用cookie存储重启依然有效
	engine.Use(sessions.Sessions("logto-session", store))

	engine.GET("/cookie_test", func(context *gin.Context) {
		data := map[string]string{}
		// 从gin.Context中获取Session对象 这个在每次使用的时候都需要先获取这个对象
		context.SetCookie("vmware_soap_session", "\"93a7ef403bedff5922346dc578fe1082a66bfbf6\"", -1, "/", "localhost", false, false)
		context.SetCookie("vmware_client", "VMware", -1, "/", "localhost", false, false)

		// session := sessions.Default(context)
		// 设置Session
		//	session.Set("vmware_soap_session", "Hello world")
		//session.Set("vmware_client", "VMware")
		data["setCookie"] = "true"
		context.JSON(200, data)
	})
	engine.Run(":8082")
}
